<template>
  <div
    v-if="!item.hidden"
    class="aside-menu-item"
  >
    <template v-if="!visiableChildren.length">
      <el-menu-item :index="'m'+item.id">
        <span slot="title">{{ item.text }}</span>
      </el-menu-item>
    </template>

    <el-submenu
      v-else
      ref="subMenu"
      :index="'m'+item.id"
      :show-timeout="0"
      :hide-timeout="0"
    >
      <template slot="title">
        <span> {{ item.text }}</span>
      </template>
      <aside-menu-item
        v-for="child in visiableChildren"
        :key="child.id"
        :item="child"
        class="nest-menu"
      />
    </el-submenu>
  </div>
</template>

<script>
export default {
  name: 'AsideMenuItem',
  props: {
    item: {
      type: Object,
      required: true
    }
  },
  data() {
    // To fix https://github.com/PanJiaChen/vue-admin-template/issues/237
    return {}
  },
  computed: {
    visiableChildren() {
      var children = this.item.children || []
      if (children.length > 0) {
        var nn = children.filter(item => {
          return !item.hidden
        })
        return nn
      }
      return children
    }
  },
  methods: {}
}
</script>
